package DynamicCrawler;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;


public class JsoupDemo {
    public static ArrayList<String> geturl(String url) {
        ArrayList<String> u = new ArrayList<>();
        try {
            Document doc = Jsoup.connect(url)
                    .userAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.15)")
                    .timeout(5000).get();
            Elements hrefs = doc.select("a[href]");
            for (Element elem : hrefs) {
               u.add(elem.attr("abs:href"));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return u;
    }

    public static void main(String[] args) {
        String url = "http://db.auto.sina.com.cn/car_manual/242/";
        ArrayList<String> list = geturl(url);
        for(int i = 0; i < list.size(); i++){
            System.out.println(list.get(i));
        }
    }
}